VOISSayas =
{
    /*
        Sayas Text
    */
    sayasAttribute : new String("x-awwwe-browser-sayas"),
    sayasTextDivId : new String("awwwe-browser-vois-wizard-form-div-sayas-text"),
    sayasAtSectionDivId : new String("awwwe-browser-vois-wizard-form-div-sayas-at"),
    sayasTextSectionDivId : new String("awwwe-browser-vois-wizard-form-div-sayas-text"),

	SayasTextRemove : function(id)
	{
        var ok, id, node;
        
        ok = confirm("Remove this say as?");
        if (ok)
        {
            node = document.getElementById(id);
            node.parentNode.removeChild(node);
            this.currentlySelectedSayasTextNode = null;
        }
	},
    currentSayasTextId : 0,
    BuildSayasTextDivId : function()
    {
        var n = this.currentSayasTextId;
        this.currentSayasTextId++;
        return this._BuildSayasTextDivId(n);
    },
    _BuildSayasTextDivId : function(n)
    {
        return VOISEditor.formId.concat("div-sayas-text").concat(n.toString());
    },
    BuildSayasTextSayasId : function(sayasTextDivId)
    {
        return sayasTextDivId + "input-sayas";
    },
    BuildSayasTextAtId : function(sayasTextDivId)
    {
        return sayasTextDivId + "input-at";
    },
    RemoveSectionsSayAsText : function ()
    {
        for (var i=0; i<this.currentSayasTextId; i++)
        {
            var id = this._BuildSayasTextDivId(i);
            var node = document.getElementById(id);
            if (node != null)
            {
                node.parentNode.removeChild(node);
            }
        }
        this.currentSayasTextId = 0;
    },
    AddSectionSayasText : function(sayas, text)
    {
        var node = document.getElementById(this.sayasTextSectionDivId);
        var childNode = this.NewSayasTextDiv(sayas, text);
        node.appendChild(childNode);
    },
    currentlySelectedSayasTextNode : null,
    NewSayasTextDiv : function(sayas, findText)
    {
        var control, div, id, sayasTextDivId, p, br, label;

        div = document.createElement("div");
        sayasTextDivId = this.BuildSayasTextDivId();
        div.setAttribute("id", sayasTextDivId );
        div.setAttribute("class", VOISEditor.unSelectedDivClassName);
        
        // remove button
        // SayasTextRemove
        control = document.createElement("input");
        control.setAttribute("type", "button");
        control.setAttribute("value", "Remove This Sayas");
        control.setAttribute("onclick", "VOISSayas.SayasTextRemove(\"" + sayasTextDivId + "\");");
        p = document.createElement("p");
        p.appendChild(control);
        div.appendChild(p);

        // add the at text input
        control =  document.createElement("input");
        control.setAttribute("type", "text");
        id = this.BuildSayasTextAtId(sayasTextDivId);
        control.setAttribute("id", id);
        control.setAttribute("value", findText);
        control.setAttribute("onFocus", "VOISSayas.SayasTextSectionDivSelect(\"" + sayasTextDivId + "\");");
        
        p = document.createElement("p");
        p.appendChild(VOISEditor.Label(id, "Text in the web page."));
        p.appendChild(control);
        div.appendChild(p);

        // sayas input
        control =  document.createElement("input");
        control.setAttribute("type", "text");
        id = this.BuildSayasTextSayasId(sayasTextDivId);
        control.setAttribute("id", id);
        control.setAttribute("value", sayas);
        control.setAttribute("onfocus", "VOISSayas.SayasTextSectionDivSelect(\"" + sayasTextDivId + "\");");

        p = document.createElement("p");
        p.appendChild(VOISEditor.Label(id, "Say this instead."));

        p.appendChild(control);
        div.appendChild(p);
        
        // add the div to the sayas at section fo the form
        var sayasTextSectionDiv = document.getElementById(this.sayasTextSectionDivId);
        sayasTextSectionDiv.appendChild(div);
        sayasTextSectionDiv.style.display = "block";

        return div;
    },
    SayasTextSectionDivCurrentOff : function ()
    {
        if (this.currentlySelectedSayasTextNode != null)
        {
            // turn off the current sayas at section
            // turn off div outside the paragraph of the old control
            this.currentlySelectedSayasTextNode.setAttribute("class", VOISEditor.unSelectedDivClassName);
            // turn off the paragraph that the old control is in
            var oldSectionID = this.currentlySelectedSayasTextNode.getAttribute("id");
            var oldControlNodeId = this.BuildSayasTextAtId(oldSectionID);
            var oldControlNode = document.getElementById(oldControlNodeId);
            oldControlNode.parentNode.setAttribute("class", this.unSelectedControlClassName);
            this.currentlySelectedSayasTextNode = null;
        }
    },
    SayasTextSectionDivSelect : function (id)
    {
        var newDivNode = document.getElementById(id);
        
        // the user clicked on the sayas-at at input in the form
        if (
            this.currentlySelectedSayasTextNode != null
            && this.currentlySelectedSayasTextNode != newDivNode
        )
        {
            this.SayasTextSectionDivCurrentOff();
        }
        
        // turn on the new sayas section in the form.
        newDivNode.setAttribute("class", VOISEditor.selectedDivClassName);
        
        this.currentlySelectedSayasTextNode = newDivNode;
    },
    SayasTextControlUnSelect : function ()
    {
        if (this.currentlySelectedSayasTextNode != null)
        {
            // turn off div outside the paragraph
            this.currentlySelectedSayasTextNode.parentNode.parentNode.setAttribute("class", VOISEditor.unSelectedDivClassName);
            this.currentlySelectedSayasTextNode = null;
        }
    },
    UserSelectSayasFromWebPage : function ()
    {
        
    },

    /*
        Sayas At
    */
    SetXpathSayas : function(xpath, setting)
    {
        var xpathResult = VOISXPath._SingleXpathExpressionNodeSet(xpath, true);
        if (xpathResult != null && xpathResult.snapshotLength > 0)
        {
            for (var i=0; i < xpathResult.snapshotLength; i++ )  
            {
                var childNode = xpathResult.snapshotItem(i);
                var id = childNode.getAttribute("x-awwwe-browser-id");
                if (id.length > 0)
                {
                    childNode.setAttribute(this.sayasAttribute, setting);
                }
            }
        }
    },
    
	SayasAtRemove : function(id)
	{
        var ok = confirm("Remove this say as?");
        if (ok)
        {
            // get xpath expression and the node
            var node = document.getElementById(id);
            if (node != null)
            {
                var atId = this.BuildSayasAtAtId(id);
                var atNode = document.getElementById(atId);
                var xpath = atNode.value.trim();
                this.SetXpathSayas(xpath, "");
                node.parentNode.removeChild(node);
                this.currentlySelectedSayasAtNode = null;
            }
        }
	},
    
    RemoveSectionsSayAsAt : function ()
    {
        for (var i=0; i<this.currentSayasAtId; i++)
        {
            var id = this._BuildSayasAtDivId(i);
            var node = document.getElementById(id);
            if (node != null)
            {
                var atId = this.BuildSayasAtAtId(id);
                var atNode = document.getElementById(atId);
                var xpath = atNode.value.trim();
                this.SetXpathSayas(xpath, "");
                node.parentNode.removeChild(node);
            }
        }
        this.currentSayasAtId = 0;
    },

    currentSayasAtId : 0,
    BuildSayasAtDivId : function()
    {
        var n = this.currentSayasAtId;
        this.currentSayasAtId++;
        return this._BuildSayasAtDivId(n);
    },
    _BuildSayasAtDivId : function(n)
    {
        return VOISEditor.formId.concat("div-sayas-at").concat(n.toString());
    },
    BuildSayasAtSayasId : function(sayasAtDivId)
    {
        return sayasAtDivId + "input-sayas";
    },
    BuildSayasAtAtId : function(sayasAtDivId)
    {
        return sayasAtDivId + "input-at";
    },

    AddSectionSayasAt : function(sayas, at)
    {
        var node = document.getElementById(this.sayasAtSectionDivId);
        var childNode = this.NewSayasAtDiv(sayas, at);
        node.appendChild(childNode);
    },
    currentlySelectedSayasAtNode : null,
    NewSayasAtDiv : function(sayas, at)
    {
        var control, div, id, atId, sayasAtDivId, p, br, label;

        div = document.createElement("div");
        sayasAtDivId = this.BuildSayasAtDivId();
        div.setAttribute("id", sayasAtDivId );
        div.setAttribute("class", VOISEditor.unSelectedDivClassName);
        
        // remove button
        // SayasAtRemove
        control = document.createElement("input");
        control.setAttribute("type", "button");
        control.setAttribute("value", "Remove This Sayas");
        control.setAttribute("onclick", "VOISSayas.SayasAtRemove(\"" + sayasAtDivId + "\");");
        p = document.createElement("p");
        p.appendChild(control);
        div.appendChild(p);

        // sayas input
        control =  document.createElement("input");
        control.setAttribute("type", "text");
        id = this.BuildSayasAtSayasId(sayasAtDivId);
        control.setAttribute("id", id);
        control.setAttribute("value", sayas);
        control.setAttribute("onfocus", "VOISSayas.SayasAtSectionDivSelect(\"" + sayasAtDivId + "\");");

        p = document.createElement("p");
        p.appendChild(VOISEditor.Label(id, "Say"));

        p.appendChild(control);
        div.appendChild(p);


        // add the at textarea
        control =  document.createElement("input");
        control.setAttribute("type", "text");
        control.setAttribute("readonly", "readonly");
        atId = this.BuildSayasAtAtId(sayasAtDivId);
        control.setAttribute("id", atId);
        control.setAttribute("value", at);
        control.setAttribute("class", "awwwe-browser-vois-wizard-form-sayas-say-at");
        control.setAttribute("onFocus", "VOISSayas.SayasAtSectionDivSelect(\"" + sayasAtDivId + "\");");
        
        p = document.createElement("p");
        p.appendChild(VOISEditor.Label(id, "At"));
        p.appendChild(control);
        div.appendChild(p);
        
        // add the div to the sayas at section fo the form
        var sayasAtSectionDiv = document.getElementById(this.sayasAtSectionDivId);
        sayasAtSectionDiv.appendChild(div);
        sayasAtSectionDiv.style.display = "block";
        
        // set the sayas attribute in the web page
        var atNode = document.getElementById(atId);
        var xpath = atNode.value.trim();
        this.SetXpathSayas(xpath, sayas);
        

        return div;
    },
    SayasAtSectionDivCurrentOff : function ()
    {
        if (this.currentlySelectedSayasAtNode != null)
        {
            // turn off the current sayas at section
            // turn off div outside the paragraph of the old control
            this.currentlySelectedSayasAtNode.setAttribute("class", VOISEditor.unSelectedDivClassName);
            // turn off the paragraph that the old control is in
            var oldSectionID = this.currentlySelectedSayasAtNode.getAttribute("id");
            var oldControlNodeId = this.BuildSayasAtAtId(oldSectionID);
            var oldControlNode = document.getElementById(oldControlNodeId);
            oldControlNode.parentNode.setAttribute("class", this.unSelectedControlClassName);
            this.currentlySelectedSayasAtNode = null;
        }
    },
    SayasAtSectionDivSelect : function (id)
    {
        var newDivNode = document.getElementById(id);
        
        // the user clicked on the sayas-at at input in the form
        if (
            this.currentlySelectedSayasAtNode != null
            && this.currentlySelectedSayasAtNode != newDivNode
        )
        {
            this.SayasAtSectionDivCurrentOff();
        }
        
        // turn on the new sayas section in the form.
        newDivNode.setAttribute("class", VOISEditor.selectedDivClassName);
        this.currentlySelectedSayasAtNode = newDivNode;
    },
    SayasAtControlUnSelect : function ()
    {
        if (this.currentlySelectedSayasAtNode != null)
        {
            // turn off div outside the paragraph
            this.currentlySelectedSayasAtNode.parentNode.parentNode.setAttribute("class", VOISEditor.unSelectedDivClassName);
            // turn on div outside the paragraph
            node.parentNode.parentNode.setAttribute("class", VOISEditor.selectedDivClassName);
            this.currentlySelectedSayasAtNode = null;
        }
    },
    UserSelectSayasFromWebPage : function ()
    {
        
    }
}